﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace UCS.XNA.Utils
{
    public static class Texture2DCreator
    {
        #region Static Methods

        public static Texture2D FromGradient(Color beginColor, Color endColor, GraphicsDevice graphicsDevice)
        {
            Color[] colorVector = new Color[128 * 128];

            for (int i = 0; i < colorVector.Length; i++)
            {
                float percent = (float)i / (float)colorVector.Length;
                int red = beginColor.R + (int)(percent * (endColor.R - beginColor.R));
                int green = beginColor.G + (int)(percent * (endColor.G - beginColor.G));
                int blue = beginColor.B + (int)(percent * (endColor.B - beginColor.B));

                colorVector[i] = new Color(red, green, blue, 255);
            }

            Texture2D texture = new Texture2D(graphicsDevice, 128, 128);
            texture.SetData(colorVector);

            return texture;
        }

        public static Texture2D FromColor(Color color, GraphicsDevice graphicsDevice)
        {
            Color[] colorVector = new Color[1] { color };

            Texture2D texture = new Texture2D(graphicsDevice, 1, 1);
            texture.SetData(colorVector);

            return texture;
        }

        #endregion
    }
}